$(document).ready(function () {
    query();
    select();
    courseType();
});

function select() {
    $(document).on('click', '#selectMark', function () {
        //var $stuInfoId=5;
        var tbody = $("#txug");
        var termYear = $("#termYear option:selected").val();
        var termNum = $("#termNum option:selected").val();
        var courseType = $("#courseType option:selected").val();
        var courseId = $("#courseId").val();
        var courseName = $("#courseName").val();
        var url = "http://localhost:8080/mark/selectFailGrade?stuInfoId=" + 5 + "&termYear=" + termYear + "&termNum=" + termNum + "&courseType=" + courseType + "&courseId=" + courseId + "&courseName=" + courseName;
        var table = $('#dataTable').dataTable()
        if (table) {
            table.fnDestroy();
        }

        $('#dataTable').dataTable({

            "processing": true,
            "serverSide": true,
            "bInfo": false,//是否显示是否启用底边信息栏
            "sAjaxDataProp": "data.markList",
            "sAjaxSource": url,
            "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
            "fnPreDrawCallback": function (oSettings) {
                $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
                $('.dataTables_length select').addClass('form-control input-small');
            },
            "oLanguage": {
                "sSearch": "",
                "sLengthMenu": "<span>_MENU_ entries</span>",
                "sZeroRecords": "暂无相关信息",
            },
            "bJQueryUI": false,
            'bAutoWidth': false,
            "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",
            "aoColumns": [
                {"mDataProp": "markId"},
                {"mDataProp": "termYear"},
                {"mDataProp": "termNum"},
                {"mDataProp": "courseId"},
                {"mDataProp": "courseName"},
                {"mDataProp": "courseType"},
                {"mDataProp": "courseCredithour"},
                {"mDataProp": "mark"},
                //zkl修改
                {
                    "mDataProp": "applyMarkCheckState",
                    "mRender": function (data) {
                        if (data == 1) {
                            return "<span  class='badge badge-danger mr10 mb10'  onclick=\"showNote()\" id='applied'>已申请</span>";
                        }
                        if (data == 0) {
                            return "<a href='#'><span  class='badge badge-danger mr10 mb10' onclick=\"reloadPage()\" id='applyMarkCheck' >申请</span></a>";
                        }
                    }
                }
            ],
        })

    });
};
//成绩查询页面--所有不及格成绩
var query = function () {
    $('#dataTable').dataTable({
        "bDeferRender": true,
        "sAjaxDataProp": "data.markList",
        "sAjaxSource": "http://localhost:8080/mark/selectFailGrade?stuInfoId=" + 5,
        "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
        "fnPreDrawCallback": function (oSettings) {
            $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
            $('.dataTables_length select').addClass('form-control input-small');
        },
        "oLanguage": {
            "sSearch": "",
            "sLengthMenu": "<span>_MENU_ entries</span>",
            "sZeroRecords": "暂无相关信息",
        },
        "bJQueryUI": false,
        "bAutoWidth": false,
        "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",
        "aoColumns": [
            {"mDataProp": "markId"},
            {"mDataProp": "termYear"},
            {"mDataProp": "termNum"},
            {"mDataProp": "courseId"},
            {"mDataProp": "courseName"},
            {"mDataProp": "courseType"},
            {"mDataProp": "courseCredithour"},
            {"mDataProp": "mark"},
            //zkl修改
            {
                "mDataProp": "applyMarkCheckState",
                "mRender": function (data) {
                    if (data == 1) {
                        return "<span  class='badge badge-danger mr10 mb10'  onclick=\"showNote()\" id='applied'>已申请</span>";
                    }
                    if (data == 0) {
                        return "<a href='#'><span  class='badge badge-danger mr10 mb10' onclick=\"reloadPage()\" id='applyMarkCheck' >申请</span></a>";
                    }
                }
            }
        ],
    })
};

//下拉列表获取课程类别
function courseType() {
    var cType = $("#courseType");
    $.ajax({
        url: "http://localhost:8080/mark/selectCourseType",
        type: "GET",
        async: false,
        dataType: "json",
        success: function (data) {
            var str = "";
            d = data.data;
            ctype = d[1]
            for (x in ctype) {
                str += "<option value='" + ctype[x].courseType + "'>" + ctype[x].courseType + "</option>"
            }
            cType.append(str);
        },
        error: function () {
            layer.alert("暂无记录")
        }
    })
}

//-----赵开兰开始----------
//申请不及格成绩复查
$(document).on('click', '#applyMarkCheck', function () {
        //alert("------------");
        //获得成绩id
        var $MarkID = $(this).parents("tr").children(0).eq(0).text();
        alert($MarkID);
        $.ajax({
            type: "GET",   //以get形式向后台传递表单
            url: "http://localhost:8080/markCheck/applyMarkCheck",//数据传输的目的地址，将在这里对前台数据进行操作
            data: "markID=" + $MarkID,
            //  data: {'MarkID': 83}, //这里是前台传到后台的数据
            dataType: "json",
            success: function (data) {
                $("#applyMarkCheck").html("已申请");
                console.log(data)
                layer.alert("申请复查已提交，请等待老师复查。")
            },
            error:
                function () {
                    layer.alert("申请复查失败，请重试。")
                }
        });
        alert("end------")
    }
);

//点击申请复查的同时刷新页面
function reloadPage() {
    window.location.reload();
};

//学生点击已申请的成绩申请，弹出提示信息
function showNote() {
    layer.alert("该成绩已提交过申请复查，不能再次申请。")
};
